package com.hy.mvc.web.conroller;

import com.hy.mvc.biz.service.manager.base.JedisCacheManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <pre>
 *    author  : Booker
 *    time    : 2017/12/11 19:32
 *    desc    : 输入描述
 *    version : v1.0
 * </pre>
 */
@Controller
@RequestMapping("test")
@Api("Redis操作---Api")
public class RedisController {

    private static final Logger logger = LoggerFactory.getLogger(RedisController.class);

    @Resource
    private JedisCacheManager jedisCacheManager;

    @RequestMapping(value = "/redis", method = RequestMethod.GET)
    @ApiOperation("测试redis 常用操作")
    public @ResponseBody
    List<String> testRedis(ModelMap modelMap) {
        //String---String
        List<String> list = new ArrayList<>();
        boolean is = jedisCacheManager.set("test", "12345", 5);
        System.out.println("s*********************set " + is);
        String value = jedisCacheManager.get("test", 5);
        System.out.println("s*********************value " + value);
        list.add(value);
        //hash
        long t1 = jedisCacheManager.hset("123", "456", "789", 1);
        long t2 = jedisCacheManager.hset("123", "789", "456", 1);
        System.out.println("s*********************t1 " + t1 + "*******t2" + t2);
        String t1_1 = jedisCacheManager.hget("123", "456", 1);
        String t2_1 = jedisCacheManager.hget("123", "789", 1);
        list.add(t1_1);
        list.add(t2_1);
        System.out.println("s*********************t1_1 " + t1_1 + "********" + t2_1);
        return list;
    }
}
